package com.teacher.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teacher.common.CommonResult;
import com.teacher.mapper.TermMapper;
import com.teacher.pojo.dto.job.JobGetDto;
import com.teacher.pojo.entity.Job;
import com.teacher.mapper.JobMapper;
import com.teacher.pojo.vo.job.JobGetVo;
import com.teacher.service.IJobService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 学生干部任职 服务实现类
 * </p>
 *
 * @author zfm
 * @since 2021-08-04
 */
@Service
public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements IJobService {

    @Autowired
    private TermMapper termMapper;

    /**
     * 查询学生干部任职
     *
     * @param dto
     * @return
     */
    @Override
    public CommonResult<IPage<JobGetVo>> getPage(JobGetDto dto) {
        Page<JobGetVo> page = new Page<>(dto.getCurrentPage(), dto.getPageSize());
        if (dto.getTermId() == null) {
            dto.setTermId(termMapper.getCurrentTerm());
        }
        IPage<JobGetVo> iPage = baseMapper.getPage(page, dto);
        return CommonResult.success(iPage);
    }
}
